// 处理全字段搜索的搜索
export const configToSearch = (colunm) =>{
	let copyColumn = JSON.parse(JSON.stringify(colunm))
    // 先做删除处理
    copyColumn = copyColumn.filter((el,index)=>{
        return el.prop != 'crZoningCode' && el.custome != 'divider' && el.type != 'dynamic' && el.type !=  'dynamicForm' && !(el.type == 'DividerHtml'&&(copyColumn[index+1].type == 'dynamic' || copyColumn[index+1].type == 'dynamicForm'))
    })
	if(copyColumn){
		copyColumn.forEach((el,index) => {
			el.span = 24
			// el.rules = []
            el.labelPosition='top'
			el.isZonghe = true
            if(el.append){
                el.inNum = true
            }
            if(el.isNum || el.append){
				el.label = el.label+'区间'
				el.prop = el.prop + 'Between'
				el.type = 'RangeValue'
			}
            if(el.type == 'input' || el.type=='text'){
                el.rules = []
            }
            if(el.label=='关键词'){
                el.type="input"
                el.rules = []
            }
			if(el.type=='upload' || el.custome == 'file' || el.custome == 'img'){
                el.rules = []
				delete el.showFileList
				delete el.limit
				el.type = 'select'
				el.prop = el.prop
				el.label = '是否存在'+(el.uploadTip || el.label)
				el.dicData = [{label:'是',value:"1"},{label:'否',value:"0"}]
				el.multiple = true
			}
			if(el.type == 'remoteSelect'|| el.type == 'redio'|| el.type == 'select'){
                el.rules = []
				el.multiple = true
				el.prop = el.prop+'List'
				delete el.propName
			}
            if(el.dicData){
                el.rules = []
                el.dicData.forEach(el=>{
                    if(el.value){
                        el.value = String(el.value)
                    }
                })  
            }
			if(el.type === 'AplidAreaSelect'){
                el.rules = []
				el.multiple = true
				// el.prop = 'crAreaId'
                el.regionGrade = 3
				el.checkStrictly = false
				el.showAllLevels = false
				delete el.propName
                if(el.label == '户籍区划' || el.label == '户籍地区' || el.label=='家庭床位用户户籍地区' ){
                    el.prop = 'crAreaIdList'
                }
                if(el.label == '所属区域' || el.label =="改造地区" || el.label == '居住地区'|| el.label=='家庭床位用户现居地区'|| el.label == '服务地区'|| el.label == '现居地区'){
                    el.prop = 'areaIdList'
                }
                
                if(el.label == '所在地区' || el.label=='机构所属区域' || el.label == '设施所属地区'|| el.label =="所属区划"){
                    el.prop = 'belongAreaIdList'
                }
                if(el.label == '来源单位区划'){
                    el.prop = 'fromAreaIdList'
                }

			}
            if(el.type=='textarea' || el.type=='text' || el.type == 'ueditor'){
                el.rules = []
                if(Number(el.maxlength)>140){
                    el.maxlength = '140'
                }
                el.type = 'text'
            }
			
            if(el.type == 'date' || el.type=='datetime'){
                el.rules = []
                el.label = el.label+'区间'
				el.prop = el.prop + 'Between'
                el.type = el.type+'range'
                if(el.type == 'date'){
                    el.format = 'YYYY年MM月DD日'
                    el.valueFormat = 'YYYY-MM-DD'
                }
                if(el.type == 'datetime'){
                    el.format = 'YYYY年MM月DD HH时mm分ss'
                    el.valueFormat = 'YYYY-MM-DD HH-mm-ss'
                }
            }
            if(el.propOther){
               delete el.propOther
            }
            if(el.append == '百分比'){
                el.label =  el.label+ '(请输入0-1之间的数值)'
            }
            // if(el.custome == 'divider'){
            //     // 去除分割线
            //     copyColumn.splice(index,1)
            // }
            // 如果是一对多
            // if(el.type == 'dynamic' || el.type ==  'dynamicForm'){
            //     copyColumn.splice(index,1)
            // }
           
            // if(el.type == 'dynamic' || el.type ==  'dynamicForm'){
            //   el.label = copyColumn[index-1].label
            //   if(el.column){
            //     let res = configToSearch(el.column)
            //     res.forEach((item,ind)=>{
                   
            //         copyColumn.splice(index+ind+1,1,item)
            //     })
            //     copyColumn.splice(index,1)
            //   }
            //   copyColumn.splice(index,1)
            // }
		})
	}
	return copyColumn
}
// 处理全字段查缺补漏
export const configToReserveSearch = (colunm) =>{
	let copyColumn = JSON.parse(JSON.stringify(colunm))
    copyColumn = copyColumn.filter((el,index)=>{
        return el.prop != 'crZoningCode' && el.custome != 'divider' && el.type != 'dynamic' && el.type !=  'dynamicForm' && !(el.type == 'DividerHtml'&&(copyColumn[index+1].type == 'dynamic' || copyColumn[index+1].type == 'dynamicForm'))
    })
	if(copyColumn){
		copyColumn.forEach((el,index) => {
			el.rules = []
            el.labelPosition='left'
			el.isChaQue = true
            // if(el.custome == 'divider'){
            //     // 去除分割线
            //     copyColumn.splice(index,1)
            // }
            // if(el.type == 'dynamic' || el.type ==  'dynamicForm'){
            //     if(el.column){
            //         let res = configToReserveSearch(el.column)
            //         res.forEach((item,ind)=>{
            //             copyColumn.splice(index+ind+1,1,item)
            //         })
            //         copyColumn.splice(index,1)
            //       }
            // }else 
            if(el.propOther){
                delete el.propOther
             }
            if(el.type === 'AplidAreaSelect'){
                
                if(el.label == '户籍区划' || el.label == '户籍地区' || el.label=='家庭床位用户户籍地区'){
                    el.prop = 'crAreaId1'
                }
                if(el.label == '所属区域' || el.label =="改造地区" || el.label == '居住地区' || el.label=='家庭床位用户现居地区'|| el.label == '服务地区'|| el.label == '现居地区'){
                    el.prop = 'areaId1'
                }
                
                if(el.label == '所在地区' || el.label=='机构所属区域' || el.label == '设施所属地区'){
                    el.prop = 'belongAreaId1'
                }
                if(el.label == '来源单位区划'){
                    el.prop = 'fromAreaId1'
                }
                
                el.type='checkbox'
                el.span=12
                el.dicData = [{label:el.label || el.uploadTip,value:1}]
                delete el.label
                delete el.uploadTip
            }
            else if(el.type!='DividerHtml'){
                el.type='checkbox'
                el.span=12
                el.prop = el.prop+'1'
                el.dicData = [{label:el.label || el.uploadTip,value:1}]
                delete el.label
                delete el.uploadTip
            } else {
                el.span=24
            }
            
        })
	}
	return copyColumn
}
// 处理全字段搜索的请求条件
export const toSearchHandle = (config,reserveConfig,query) => {
    let arr1 = Object.keys(query)
    arr1.forEach((el)=>{
        if(query[el]=='' || (Array.isArray( query[el])&&query[el].length==0)|| !query[el]){
            query[el] = undefined
        }
    })
    // 全字段搜索
    if(config.column){
        let list = config.column.filter(el=>{
			return (el.type == 'select' || el.type == 'remoteSelect'|| el.type == 'AplidAreaSelect'||el.type == 'daterange'||el.type == 'datetimerange' ) && el.isZonghe && query[el.prop]
		})
        if(list.length>0){
			list.forEach(el=>{
				if(el.type== 'remoteSelect' || el.type== 'select'){
                    if(query[el.prop]=='' && !query[el.prop]){
                        query[el.prop] = []
                    }
                    if(el.type== 'remoteSelect' && !Array.isArray(query[el.prop])){
                        query[el.prop] = query[el.prop].split(',')
                    }
				}else if(el.type == 'AplidAreaSelect'){
                   let copy = JSON.parse(JSON.stringify(query[el.prop]))
                   let arr = []
                   copy.forEach((areaList,ind)=>{
                      arr.push(areaList[2]) 
                   })
                   query[el.prop]= arr
				}else if(el.type== 'daterange' || el.type == 'datetimerange'){
                    query[el.prop] = query[el.prop].join(',')
                }
			})
		}
    }
    if(reserveConfig.column){
        let reserveList = reserveConfig.column.filter(el=>{
			return  el.isChaQue && query[el.prop]
		})
        if(reserveList.length>0){
            reserveList.forEach(el=>{
                if(query[el.prop].length>0){
                    query[el.prop] = 1 
                }else{
                    query[el.prop] = undefined
                }
                
            })
        }
    }  
    return query
}